package Thread;

class MyThread extends Thread{
    @Override
    public void run() {
        while (true){
            System.out.println("hello Thread!");
            //这里的异常不能被throws，只能try catch，因为这里的run方法是重写的父类的run方法，父类的run方法没有throws异常，所以重写也不能throws,没有这样的设定
            try {
                Thread.sleep(1000);//调用Thread的sleep静态方法
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class Demo1 {
    public static void main(String[] args) {
        MyThread myThread = new MyThread();
        myThread.start();
//        myThread.run();
        while (true){
            System.out.println("hello main");
            try {
                Thread.sleep(1000);//单位是毫秒
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
